<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <input type="text" placeholder="用户名" v-model="user.username">
  <input type="password" placeholder="密码" v-model="user.password">
  <input type="button" value="登录" @click="login()">
</div>
<!--引入vue框架文件-->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!--引入axios框架文件-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
      user:{username:"",password:""},
        li:{}
    },
    methods:{
      login(){
        //发出异步的post请求
        axios.post("/v1/users/login",v.user).then(function (response) {
          if (response.data.code==1){
            // location.href="/";//跳转到首页
              v.li = response.data.data;
              localStorage.setItem("user",JSON.stringify(response.data.data));

          }else if(response.data.code==1003){
            alert("用户名不存在!");
          }else{
            alert("密码错误!");
          }
        })
      }
    }
  })
</script>
</body>
</html>